using System;
using System.Collections.Generic;
using System.Xml;

namespace ReutersToHTML
{
    public class ReuetersDocument
    {
        public int Id { get; set; }

        public ICollection<string> Topics { get; set; }

        public string Title { get; set; }

        public string Name { get; set; }
        public string Body{ get; set; }
        private ReuetersDocument()
        {
            Topics = new List<string>();
        }
        public static ReuetersDocument GenerateDoc(XmlNode reutersNode)
        {
            ReuetersDocument doc = new ReuetersDocument();
            doc.Id = Convert.ToInt32(reutersNode.Attributes["NEWID"].Value);
            doc.Name = doc.Id + ".html";
            XmlNode topics = reutersNode.SelectSingleNode("TOPICS");
            foreach (XmlNode topic in topics)
            {
                doc.Topics.Add(topic.InnerText);
            }
            XmlNode text = reutersNode.SelectSingleNode("TEXT");
            XmlNode title = text.SelectSingleNode("TITLE");
            doc.Title = title != null ? title.InnerXml : string.Empty;
            XmlNode body = text.SelectSingleNode("BODY");
            if (body != null)
            {
                doc.Body = text.SelectSingleNode("BODY").InnerXml;
            }
            else return null;
            return doc;
        }
    }
}